from selenium import webdriver
from lxml import etree
import time

bro = webdriver.Chrome('web_pa\chromedriver.exe')
url = 'https://www.taobao.com'
page_text = bro.get(url)

# 标签定位搜索框
search_input = bro.find_element_by_id('q')
# 标签交互
search_input.send_keys('lift')
# time.sleep(2)
# 执行script代码
bro.execute_script('window.scrollTo(0, document.body.scrollHeight)')   # 使滚轮向下滚动一页
# time.sleep(2)
# 点击搜索按钮
btt = bro.find_element_by_class_name('btn-search')
btt.click()

# 访问另一个网站后回退
bro.get('http://www.baidu.com')
bro.back()  # 后退
time.sleep(2)
bro.forward()   # 前进

# 等待几秒后关闭浏览器
time.sleep(2)
bro.quit()

